﻿$(function () {
    $(".follow:not('.gotosignin')").live("click", function () {
        $.ajax({
            type: "POST",
            url: $(this).attr("href"),
            data: "",
            success: function (data) {
                if (data.Success == 1) {
                    $(".follow").hide();
                    $(".followed").show();
                }
                return false;
            }
        })
        return false;
    })

    $(".followed").live("click", function () {
        $.ajax({
            type: "POST",
            url: $(this).attr("href"),
            data: "",
            success: function (data) {
                if (data.Success == 1) {
                    $(".followed").hide();
                    $(".follow").show();
                }
                return false;
            }
        })
        return false;
    })

    $("a.contact:not('.gotosignin')").click(function () {
        Overlay.show($(this).attr('href'));
        return false;
    });

    $('a.contacted').click(function () {
        Overlay.show($(this).attr('href'));
        return false;
    });

    $("[rel='tipsy']").tipsy({ gravity: 's', fade: true });

    $("[rel='unsave']").click(function () {
        var $link = $(this);
        $.ajax({
            type: "POST",
            url: $(this).attr("href"),
            data: "",
            success: function (data) {
                if (data.Success == 1) {
                    var container = $link.closest("ol");
                    var subContainer = $link.closest("li");
                    subContainer.remove();
                    var len = $("li", container).length;
                    //if no items in current page
                    if (len == 0) {
                        //if has next page
                        if ($("[rel='next']").length > 0) {
                            window.location.href = window.location.href;
                        }
                        else if ($("[rel='prev']").length > 0) {
                            window.location.href = $("[rel='prev']").attr("href");
                        }
                        else {
                            window.location.href = window.location.href;
                        }
                    }
                }
                return false;
            }
        })
        return false;
    })
})

function ProcessNewMessage(data) {
    JsonResultHandler.Success(data);
    if (data.Success == 1) {
        $(".contact").hide();
        $(".contacted").show();
        Overlay.hide();
    }
}
